package com.new_wear.project.system.integral.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.new_wear.framework.aspectj.lang.annotation.Log;
import com.new_wear.framework.aspectj.lang.enums.BusinessType;
import com.new_wear.project.system.integral.domain.CstUserIntegral;
import com.new_wear.project.system.integral.service.ICstUserIntegralService;
import com.new_wear.framework.web.controller.BaseController;
import com.new_wear.framework.web.domain.AjaxResult;
import com.new_wear.common.utils.poi.ExcelUtil;
import com.new_wear.framework.web.page.TableDataInfo;

/**
 * 用户 - 积分(等、消)Controller
 * 
 * @author new_wear
 * @date 2019-12-31
 */
@Controller
@RequestMapping("/system/integral")
public class CstUserIntegralController extends BaseController
{
    private String prefix = "system/integral";

    @Autowired
    private ICstUserIntegralService cstUserIntegralService;

    @RequiresPermissions("system:integral:view")
    @GetMapping()
    public String integral()
    {
        return prefix + "/integral";
    }

    /**
     * 查询用户 - 积分(等、消)列表
     */
    @RequiresPermissions("system:integral:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CstUserIntegral cstUserIntegral)
    {
        startPage();
        List<CstUserIntegral> list = cstUserIntegralService.selectCstUserIntegralList(cstUserIntegral);
        return getDataTable(list);
    }

    /**
     * 导出用户 - 积分(等、消)列表
     */
    @RequiresPermissions("system:integral:export")
    @Log(title = "用户 - 积分(等、消)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CstUserIntegral cstUserIntegral)
    {
        List<CstUserIntegral> list = cstUserIntegralService.selectCstUserIntegralList(cstUserIntegral);
        ExcelUtil<CstUserIntegral> util = new ExcelUtil<CstUserIntegral>(CstUserIntegral.class);
        return util.exportExcel(list, "integral");
    }

    /**
     * 新增用户 - 积分(等、消)
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户 - 积分(等、消)
     */
    @RequiresPermissions("system:integral:add")
    @Log(title = "用户 - 积分(等、消)", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CstUserIntegral cstUserIntegral)
    {
        return toAjax(cstUserIntegralService.insertCstUserIntegral(cstUserIntegral));
    }

    /**
     * 修改用户 - 积分(等、消)
     */
    @GetMapping("/edit/{uid}")
    public String edit(@PathVariable("uid") Long uid, ModelMap mmap)
    {
        CstUserIntegral cstUserIntegral = cstUserIntegralService.selectCstUserIntegralById(uid);
        mmap.put("cstUserIntegral", cstUserIntegral);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户 - 积分(等、消)
     */
    @RequiresPermissions("system:integral:edit")
    @Log(title = "用户 - 积分(等、消)", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CstUserIntegral cstUserIntegral)
    {
        return toAjax(cstUserIntegralService.updateCstUserIntegral(cstUserIntegral));
    }

    /**
     * 删除用户 - 积分(等、消)
     */
    @RequiresPermissions("system:integral:remove")
    @Log(title = "用户 - 积分(等、消)", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cstUserIntegralService.deleteCstUserIntegralByIds(ids));
    }
}
